package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbUserMapper;
import com.dongdongshop.pojo.TbUser;
import com.dongdongshop.pojo.TbUserExample;
import com.dongdongshop.service.TbUserService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class TbUserServiceImpl implements TbUserService {

    //注入mapper
    @Autowired
    private TbUserMapper tbUserMapper;

    //查看账号是否存在
    @Override
    public TbUser findTbAdminByName(String username) {
        TbUserExample te = new TbUserExample();
        TbUserExample.Criteria criteria = te.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<TbUser> tbUsers = tbUserMapper.selectByExample(te);
        return tbUsers.size() == 0 ? null : tbUsers.get(0);
    }

    //注册逻辑
    @Override
    public void add(TbUser tbAdmin) {
        tbUserMapper.insertSelective(tbAdmin);
    }
}
